#include <vector>
#include "Core/Array/Array.h"
#include "Core/Time/TimeMeasure.h"
#include "Core/Thread/Mutex.h"
#include "ArraySpeedTest.h"

const char * ArraySpeedTest::GetName() const
{
	return "Array Speed Test";
}

void ArraySpeedTest::Execute()
{
	TimeMeasure tm;

	{
		std::vector<int> array1;

		tm.AddMeasure();
		tm.Start(0);
		for(int i=0; i<10000; ++i)
			array1.push_back(i);
		tm.Stop(0);

		Array<int> array2;

		tm.AddMeasure();
		tm.Start(1);
		for(int i=0; i<10000; ++i)
			array2.Push_Back(i);
		tm.Stop(1);

		LOG_INFO("  Push_Back :");
		LOG_INFO("    - std::vector : %f", tm.GetMeasure(0));
		LOG_INFO("    - Array       : %f", tm.GetMeasure(1));

		tm.AddMeasure();
		tm.Start(2);
		for(int i=0; i<10000; ++i)
			array1.pop_back();
		tm.Stop(2);

		tm.AddMeasure();
		tm.Start(3);
		for(int i=0; i<10000; ++i)
			array2.Pop_Back();
		tm.Stop(3);
		LOG_INFO("  Pop_Back :");
		LOG_INFO("    - std::vector : %f", tm.GetMeasure(2));
		LOG_INFO("    - Array       : %f", tm.GetMeasure(3));
	}
	{
		std::vector<int> array1(10000);

		tm.AddMeasure();
		tm.Start(4);
		for(int i=0; i<10000; ++i)
			array1[i]=i;
		tm.Stop(4);

		Array<int> array2(10000);

		tm.AddMeasure();
		tm.Start(5);
		for(int i=0; i<10000; ++i)
			array2[i]=i;
		tm.Stop(5);

		LOG_INFO("  operator [] :");
		LOG_INFO("    - std::vector : %f", tm.GetMeasure(4));
		LOG_INFO("    - Array       : %f", tm.GetMeasure(5));
	}
}
